package com.fcscs.cservice.gwt.server;

import java.util.Date;
import java.util.List;

import com.fcscs.core.common.SearchResultsContainer;
import com.fcscs.core.gwt.server.FcsRemoteServiceServlet;
import com.fcscs.core.system.ApplicationContextHolder;
import com.fcscs.core.util.CommonUtil;
import com.fcscs.cservice.domain.model.CheckInConfiguration;
import com.fcscs.cservice.domain.model.CheckOutConfiguration;
import com.fcscs.cservice.domain.model.FolioView;
import com.fcscs.cservice.domain.model.MessageIdAndStatus;
import com.fcscs.cservice.domain.model.MessageView;
import com.fcscs.cservice.domain.model.RCView;
import com.fcscs.cservice.domain.model.ReservationConf;
import com.fcscs.cservice.domain.model.ReservationView;
import com.fcscs.cservice.gwt.client.ReservationService;
import com.fcscs.cservice.service.ReservationManager;

@SuppressWarnings("serial")
public class ReservationServiceImpl extends FcsRemoteServiceServlet implements ReservationService{

	private ReservationManager rsvMgr = (ReservationManager)ApplicationContextHolder.getBeanFromContext("reservationManager");

	@Override
	public SearchResultsContainer<ReservationView> findReservations(String term, Long rsvStatusId, Date startTime, Date endTime,
			int start, int resultCnt) {
		Long propId = CommonUtil.getUserContext().getPropertyId();
		List<ReservationView> views = rsvMgr.findReservations(propId, term, rsvStatusId, startTime, endTime, start, resultCnt);
		int count = rsvMgr.findReservationsCnt(propId, term, rsvStatusId, startTime, endTime);
		return new SearchResultsContainer<ReservationView>(views, count);
	}

	@Override
	public SearchResultsContainer<ReservationView> findReservations(String firstName, String lastName, Long rsvStatus,
			String roomNo, String memberNo, Long roomStatus, String baggageNo, Date arrivDate, Date departDate, Date eta, Date etd,
			Date date, int start, int resultCnt) {
		Long propId = CommonUtil.getUserContext().getPropertyId();
		List<ReservationView> views = rsvMgr.findReservations(propId, firstName, lastName, rsvStatus, roomNo, memberNo, roomStatus,
				baggageNo, arrivDate, departDate, eta, etd, date, date, start, resultCnt);
		int count = rsvMgr.findReservationsCnt(propId, firstName, lastName, rsvStatus, roomNo, memberNo, roomStatus, baggageNo,
				arrivDate, departDate, eta, etd, date, date);
		return new SearchResultsContainer<ReservationView>(views, count);
	}

	@Override
	public SearchResultsContainer<ReservationView> findRsvForFolio(String firstName, String lastName, Long rsvStatusId, String roomNo,
			Date arrivStart, Date arrivEnd, Date departStart, Date departEnd, Date date, int start, int resultCnt) {
		Long propId = CommonUtil.getUserContext().getPropertyId();
		List<ReservationView> views = rsvMgr.findRsvForFolio(propId, firstName, lastName, rsvStatusId, roomNo, arrivStart, arrivEnd,
				departStart, departEnd, date, start, resultCnt);
		int count = rsvMgr.findRsvForFolioCnt(propId, firstName, lastName, rsvStatusId, roomNo, arrivStart, arrivEnd, departStart,
				departEnd, date);
		return new SearchResultsContainer<ReservationView>(views, count);
	}

	@Override
	public RCView updateRC(RCView rc) {
		rc.setOrgId(CommonUtil.getUserContext().getOrgId());
		rc.setPropertyId(CommonUtil.getUserContext().getPropertyId());
		return rsvMgr.updateRCView(rc, null, null);
	}

	@Override
	public List<MessageView> getMessages(long rsvId) {
		return rsvMgr.getMessages(rsvId);
	}

	@Override
	public List<MessageIdAndStatus> updateMessages(List<MessageIdAndStatus> messageList) {
		return rsvMgr.updateMessages(messageList);
	}

	@Override
	public boolean expressCheckIn(long rsvId, RCView rc) {
		return rsvMgr.expressCheckIn(rsvId, rc);
	}

	@Override
	public boolean checkOut(long rsvId, FolioView folio, boolean isAuto) {
		return false;
	}

	@Override
	public boolean sendEFolio(long rsvId, long folioId) {
		return rsvMgr.sendEFolio(rsvId, folioId);
	}

	@Override
	public ReservationView getReservationView(long id) {
		return rsvMgr.getReservationView(id);
	}

	@Override
	public RCView getRCView(long id) {
		return rsvMgr.getRCView(id, CommonUtil.getUserContext().getUsername());
	}

	@Override
	public FolioView getFolioView(long id) {
		return rsvMgr.getFolioView(id);
	}

	@Override
	public ReservationConf getRsvConf(long propId) {
		return rsvMgr.getRsvConf(CommonUtil.getUserContext().getOrgId(), propId);
	}

	@Override
	public ReservationConf saveRsvConf(ReservationConf conf) {
		return rsvMgr.saveRsvConf(conf);
	}

	@Override
	public CheckInConfiguration getCheckInConf(long propId) {
		return rsvMgr.getCheckInConf(CommonUtil.getUserContext().getOrgId(), propId);
	}

	@Override
	public CheckOutConfiguration getCheckOutConf(long propId) {
		return rsvMgr.getCheckOutConf(CommonUtil.getUserContext().getOrgId(), propId);
	}

	@Override
	public CheckOutConfiguration saveCheckOutConf(CheckOutConfiguration conf) {
		return rsvMgr.saveCheckOutConf(conf);
	}
}
